﻿@using Sharp.Framework
@using Sharp.Framework.Extensions

@model MvcContrib.Pagination.IPagination<LERP.Web.Controllers.ViewModels.GoodsViewModels.GoodsSelectViewModel>
@{
    ViewBag.Title = "选择货品";
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
}
<div id="wrapper" style="float: inherit; width: 700px; padding: 5px 5px;">
    <div id="main" style="width: 100%; padding: 5px 5px; margin: 0px 0px">
        <fieldset style="width: 100%; padding: 5px 5px; margin: 0px 0px">
            <legend>选择货品 </legend>
            @using (Html.BeginForm("Select", "Goods", FormMethod.Get))
         {
                <table class="table_input" style="width: 100%;">
                 <tr>
                     <th style="width: 100px;">货品分类:</th>
                        <td style="width: 180px;">@Html.DropDownList("categoryId", (ViewBag.GoodsCategorys as List<SelectListItem>).InsertEmpty(), new { @class = "text-medium", style = "width: 99%;" })</td>
                     <th style="width: 100px;">关键字:</th>
                        <td style="width: 180px;">@Html.TextBox("keyword", "", new { @class = "text-medium", style = "width: 80%;" })</td>
                        <td>
                            <input type="submit" class="button-submit" value="查询" /></td>
                 </tr>
            </table>
         } 
@if (Model != null && Model.Any())
{
                <table class="table_list" style="width: 99%;">
        <tr>
            <th style="width: 80px;">货品编码</th>
            <th style="width: 80px;">国际条码</th>
            <th>货品名称</th>
            <th style="width: 80px;">单位</th>
            <th style="width: 80px;">单价</th>
            <th style="width: 100px;">数量</th>
            <th style="width: 50px;">操作</th>
        </tr>
        @foreach (var item in Model)
        {
                        <tr>
                            <td class="id">@item.Id</td>
                            <td class="gencod">@item.Gencod</td>
                <td  class="name" title="@item.Name">@item.Name.CutString(32)</td>
                            <td class="unit">@item.Unit</td>
                <td class="price">@item.Price</td>
                            <td>@Html.TextBox("num_" + item.Id, "10", new { @class = "text-small num", onkeyup = "this.value=this.value.replace(/\\D/g,'')", onafterpaste = "this.value=this.value.replace(/\\D/g,'')" })</td>
                
               
                            <td class="action">
                    <a id="command_@item.Id" href="#">确定</a> 
                </td>
            </tr>
        }
         
                            
    </table>
    
    <div class="page">
        @Html.Pager("page", Model.PageSize, Model.TotalItems)
    </div>
}
else
{
    <div class="empty">
                    查询信息为空
                </div>
}
    </fieldset>
  
     </div> 
                
                <div class="clear"></div>
            
</div> 
<input type="button" class="button-submit" onclick="window.close();" value="关闭" />
@section scripts
{
    <script type="text/javascript">

        $(function () {
            for (var i = 0; i < window.opener.goodsList.length; i++) {
                var item = window.opener.goodsList[i];
                $("#command_" + item.id).html("取消");
                $("#num_" + item.id).val(item.num);
            }

            //alert(window.opener.goodsList.length); 
            $(".action a").click(function () {
                 
                var $this = $(this);
                var $tr = $this.parent().parent();
                var data = {
                    id: $tr.find("td.id").html(),
                    name: $tr.find("td.name").attr("title"),
                    shortname: $tr.find("td.name").html(),
                    price: $tr.find("td.price").html(),
                    num: $tr.find("input.num").val(),
                    cnum: $tr.find("input.num").val(),
                    rnum: $tr.find("input.num").val(),
                    sellunit: $tr.find("td.unit").html(),
                    gencod: $tr.find("td.gencod").html()
                };
                if ($this.html() == "确定") {
                    $this.html("取消");
                    window.opener.goodsCommandCompleted("add", JSON.stringify(data));
                } else {
                    $this.html("确定");
                    window.opener.goodsCommandCompleted("del", JSON.stringify(data));
                }
                return false;
            });

        });



</script>

}
